import { toStringTypeCheck } from './toStringTypeCheck';

/**
 * 定义 对象 上的 一个变量
 * @param {object} that
 * @param {string} name
 * @param {PropertyDescriptor} operation
 */
function def(that, name, operation) {
  Object.defineProperty(that, name, operation);
}

/**
 * 锁定 已有 实例 函数
 * @param {object} that
 * @param {string[] | string} funcName
 */
function lock_class_func(that, funcName) {
  if (toStringTypeCheck(funcName, 'string')) {
    funcName = [funcName];
  }
  for (const funcName_i of funcName) {
    def(that, funcName_i, {
      value: that[funcName_i].bind(that),
      writable: false,
      configurable: false,
    });
  }
}

export { def, lock_class_func };
